package com.plant.serviceImpl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.plant.dao.BaseDao;
import com.plant.entity.UgcUser;
import com.plant.service.UgcUserContrallerService;


@Service
@Transactional
public class UgcUserContrallerServiceImpl implements UgcUserContrallerService{
	@Resource(name = "baseDaoImpl")
	private BaseDao basedao;

	public Long UserNewthingsCount(UgcUser user) {
		String hql="select count(id) from UgcNewthings where userId="+user.getId()+"";
		return basedao.CountHql(hql);
	}

	public Long UserFaqCount(UgcUser user) {
		String hql="select count(id) from UgcFaq where userId="+user.getId()+"";
		return basedao.CountHql(hql);
	}

	public Long UserFaqAnswerCount(UgcUser user) {
		String hql="select count(id) from UgcFaqAnswer where userId="+user.getId()+"";
		return basedao.CountHql(hql);
	}

	public List<Map<String, Object>> UserByInf(UgcUser u,Integer page,String time) {
		String sql="SELECT a.id id_key,a.user_id,b.nickname,b.photo,c.content FROM ugc_like a,ugc_user b,ugc_faq_answer" +
				" c WHERE a.user_id=b.id AND a.to_content_id=c.id AND to_user_id=183 and " +
				"to_content_type=3 AND a.create_time<'"+time+"' ORDER BY a.create_time DESC LIMIT "+(page-1)*10+",10";
		return basedao.Bysql(sql, null);
	}

	public List<Object> MyfriendIds(UgcUser u,Integer page) {
		String sql="select apply_user_id from ugc_friends a where receive_user_id="+u.getId()+" UNION " +
				"select receive_user_id from ugc_friends r where apply_user_id="+u.getId()+" LIMIT "+(page-1)*10+",10";
		return basedao.Bysql(sql, UgcUser.class);
	}



}
